package com.lly.pro.service;


import com.lly.pro.entity.User;
import com.lly.pro.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 用户相关服务
 * @author Hommond
 * @date 2/22/2019
 */

@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    @Transactional(rollbackOn = Exception.class)
    public User save(User user){
        return userRepository.save(user);
    }
    @Transactional(rollbackOn = Exception.class)
    public Integer findByUserNameAndPassword(String username,String passwoed){
        return userRepository.findByUserNameAndPassword(username,passwoed);
    }

    public Iterable<User> getAll(){
        return userRepository.findAll();
    }

    public List findUserIdByUserNameAndPassword(String userName, String password){
        return userRepository.findUserId(userName,password);
    }

    public Long findByUserIdAndPassword(Long userId, String password) {
        return userRepository.findByUserIdAndPassword(userId,password);
    }
}
